/*

* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Smart-Shop开源商城系统/ Java商城-首选电商平台系统 请务必保留此注释头信息
* |     开源地址: https://gitee.com/ningbo-qishan/gruul-mall
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     可正常分享和学习源码,未经授权 不可商用！
* |     商业版中台购买/开源版商业授权 联系技术客服
* |     官网:  https://www.73app.cn/
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Copyright (c) 2016-2999 宁波启山智软科技有限公司
* |     版权所有 ,侵权必究！
* ------------------------------------------------------------------------

*/
package com.medusa.gruul.payment.web.controller;


import com.medusa.gruul.common.core.annotation.EscapeLogin;
import com.medusa.gruul.payment.api.model.param.sft.SftCallBack;
import com.medusa.gruul.payment.service.IPaymentService;
import com.medusa.gruul.payment.service.IpsPayService;
import com.medusa.gruul.payment.service.SftPayService;
import com.medusa.gruul.payment.service.SxfPayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author whh
 * @since 2019-11-04
 */
@RestController
@RequestMapping("/")
@Api(hidden = true)
public class PaymentController {

    @Autowired
    private IPaymentService paymentService;

    @Autowired
    private IpsPayService ipsPayService;

    @Autowired
    private SxfPayService sxfPayService;

    @Autowired
    private SftPayService sftPayService;


    /**
     * 第三方回调入口
     *
     * @param request res
     * @return str
     * @throws IOException io异常
     */
    @ApiOperation(value = "支付回调入口", hidden = true)
    @PostMapping(value = "/notify")
    @EscapeLogin
    public String notify(HttpServletRequest request) throws IOException {
        String xmlResult = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding());
        return paymentService.notify(xmlResult);
    }


    /**
     * ips第三方回调入口
     *
     * @param request res
     * @return str
     */
    @ApiOperation(value = "ips支付回调入口", hidden = true)
    @PostMapping(value = "/ips_notify")
    @EscapeLogin
    public String ipsNotify(HttpServletRequest request) {
        return ipsPayService.ipsNotify(request);
    }


    /**
     * sxf第三方回调入口
     *
     * @param jsonString
     * @return str
     */
    @ApiOperation(value = "sxf支付回调入口", hidden = true)
    @PostMapping(value = "/sxf_notify")
    @EscapeLogin
    public String sxfNotify(@RequestBody String jsonString) {
        return sxfPayService.sxfNotify(jsonString);
    }


    /**
     * sft第三方回调入口
     *
     * @param sftCallBack
     * @return str
     */
    @ApiOperation(value = "sft支付回调入口", hidden = true)
    @PostMapping(value = "/sft_notify")
    @EscapeLogin
    public String sftNotify(SftCallBack sftCallBack) {
        return sftPayService.sftNotify(sftCallBack);
    }


    /**
     * 微信退款回调
     *
     * @param request
     * @throws IOException
     * @return str
     */
    @ApiOperation(value = "微信退款回调", hidden = true)
    @PostMapping(value = "/wx_refund_notify")
    @EscapeLogin
    public String wxPayRefundNotify(HttpServletRequest request) throws Exception {
        return paymentService.wxPayRefundNotify(request);
    }

}
